package com.lq.educationsystem.lqsubject.service.impl;

import com.lq.educationsystem.common.util.PageUtil;
import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultPage;
import com.lq.educationsystem.common.util.ResultPageBuild;
import com.lq.educationsystem.common.vo.TeacherSubjectPageVo;
import com.lq.educationsystem.lqsubject.entiy.TeacherSubjectTb;
import com.lq.educationsystem.lqsubject.mapper.TeacherSubjectTbMapper;
import com.lq.educationsystem.lqsubject.service.SubjectTeacherBaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubjectTeacherBaseServiceImpl implements SubjectTeacherBaseService {
    @Autowired
    TeacherSubjectTbMapper teacherSubjectTbMapper;

    @Override
    public ResultPage<TeacherSubjectTb> queryList(TeacherSubjectPageVo teacherSubjectPageVo) {
        TeacherSubjectTb teacherSubjectTb = new TeacherSubjectTb();
        //数据拷贝
        BeanUtils.copyProperties(teacherSubjectPageVo,teacherSubjectTb);
        //页面计算
        Integer page = teacherSubjectPageVo.getPage();
        Integer pageSize = teacherSubjectPageVo.getPageSize();
        //计算起始位置
        int start = PageUtil.getStart(page, pageSize);
        List<TeacherSubjectTb> teacherSubjectTbList = teacherSubjectTbMapper.queryList(teacherSubjectTb,start,pageSize);
        int counts=0;
        //查出总数
        counts = teacherSubjectTbMapper.queryCount(teacherSubjectTb);



        return ResultPageBuild.pageBuildOk(new ResultPage<TeacherSubjectTb>(),page,pageSize,counts,teacherSubjectTbList);
    }

    //插入数据
    @Override
    public void insertInfo(TeacherSubjectTb teacherSubjectTb) {
        teacherSubjectTbMapper.insert(teacherSubjectTb);

    }

    @Override
    public void updateInfo(TeacherSubjectTb teacherSubjectTb) {
        //跟新数据
        teacherSubjectTbMapper.updateByPrimaryKeySelective(teacherSubjectTb);
    }

    @Override
    public void deleteInfo(TeacherSubjectTb teacherSubjectTb) {
        Long teacherSubjectId = Long.valueOf(teacherSubjectTb.getTeacherSubjectId());
        //删除数据
        teacherSubjectTbMapper.deleteByPrimaryKey(teacherSubjectId);
    }

    /**
     * 批量查询数据
     * @param teacherSUbjectInfoIdList id集合
     * @return
     */

    @Override
    public ResultPage<TeacherSubjectTb> queryTeacherSubjectInfoByTeacherSubjectId(List<Integer> teacherSUbjectInfoIdList) {
        /**
         * 获取数据
         */

        System.out.println("teacherSUbjectInfoIdList = " + teacherSUbjectInfoIdList);


        List<TeacherSubjectTb> teacherSubjectTbList = teacherSubjectTbMapper.queryTeacherSubjectInfoByTeacherSubjectId(teacherSUbjectInfoIdList);

        ResultPage<TeacherSubjectTb> teacherSubjectTbResultPage = new ResultPage<>();
        teacherSubjectTbResultPage.setData(teacherSubjectTbList);
        return teacherSubjectTbResultPage;
    }

    @Override
    public ResultPage<TeacherSubjectTb> queryTeacherSubjectInfoByTeacherId(Integer teacherId) {
        List<TeacherSubjectTb> teacherSubjectTbList = teacherSubjectTbMapper.queryTeacherSubjectInfoByTeacherId(teacherId);
        ResultPage<TeacherSubjectTb> teacherSubjectTbResultPage = new ResultPage<>();
        teacherSubjectTbResultPage.setData(teacherSubjectTbList);
        return teacherSubjectTbResultPage;
    }
}
